<?php 
defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$tpl = new TemplatePower("template/gallery.htm");
$tpl->prepare();
$idc=intval($_REQUEST['idc']);
$tpl->assignGlobal("site_address",$site_address);

$sql="SELECT * FROM photo WHERE active=1 ORDER BY thu_tu DESC, id_photo DESC";
$db=$DB->query($sql);
$i=0;
while($rs=mysql_fetch_array($db)){
	$tpl->newBlock("thumb");
	$tpl->assign("name",$rs['name']);
	$i++;
	if($i==1) $tpl->assign("thumb1","thumb1");
	if ($rs['small_image'] && file_exists($CONFIG['upload_image_path'].$rs['small_image'])){
		$tpl->assign("image","<img alt='".$rs['name']."'  src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."'  border='0' >");		
			$tpl->assign("bigimage",$site_address.$CONFIG['upload_image_path'].$rs['image']);
	}	
	
}

$sql1="SELECT * FROM catpt".$lang." WHERE active=1 AND parentid=$idc";
$db1=$DB->query($sql1);
while($rs1=mysql_fetch_array($db1)){
	$tpl->newBlock("gallery_cell_page");
	$tpl->assign("catname",$rs1['name']);
	$sql="SELECT * FROM photo".$lang."  WHERE active=1 AND id_catpt IN (".Get_Id_CatPT($rs1['id_catpt']).") ORDER BY thu_tu DESC, id_photo DESC LIMIT 0,1";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		if ($rs['small_image']){
			$tpl->assign("image","<img  src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."'  border='0' >");
		}	
		$tpl->assign("name",$rs['name']);
		$tpl->assign("link",$site_address.$lang_dir.Get_Main_Catpt_Name($rs['id_catpt'])."_".$rs['id_catpt']."_".$idmenu.".gal");
	}

}


$tpl->printToScreen();	
?>